<template>
  <el-container class='home-box'>
    <el-header>
      <p>电商管理系统</p>
      <el-button type="info" @click='back'>退出</el-button>
    </el-header>
    <el-container class='home-con'>
      <el-aside :width="isCollapse ? '65px' : '200px'">
        <div class='menu-head' @click='isCollapse = !isCollapse'>|||</div>
        <el-menu 
          background-color='rgb(11, 180, 166)'
          text-color='#fff'
          active-text-color='#ffd04b'
          unique-opened
          router
          :default-active='activeItem'
          :collapse='isCollapse'
          :collapse-transition='false'>
          <el-submenu :index="item.id + ''" v-for='item in menuList' :key='item.id'>
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item :index="'/' + j.path " v-for='j in item.children' :key='j.id' @click='changeActive("/" + j.path)'>
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ j.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data(){
    return {
      menuList:[],
      isCollapse:false,
      activeItem:this.$route.path
    }
  },
  methods:{
    async getData(){
      let res = await this.axios.get('/menus')
      this.menuList = res.data.data
    },
    changeActive(active) {
      this.activeItem = active
    },
    back(){
      window.sessionStorage.clear()
      this.$router.push('/login')
    }
  },
  mounted(){
    this.getData()
  }
}
</script>

<style lang='scss' scoped>

.home-box {
  height:100%;
}
.el-header {
  color:white;
  background-color:rgb(11, 180, 166);
  font-size: 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-aside {
  height:100%;
  background-color:rgb(11, 180, 166);
}
.el-aside .el-menu {
  font-size: 20px;
  border-right: none;
}
.el-aside .menu-head {
  text-align:center;
  letter-spacing: 0.2em;
  font-size: 20px;
  color:#fff;
  cursor: pointer;
  padding:10px 0;
}
.home-con {
  height:calc(100% - 60px);
}
</style>